home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Demos / AirHockey / cTable.cls < prev    next >
Encoding:
Visual Basic class definition  |  2001-10-08  |  3.7 KB  |  121 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cTable"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. 'Here we will encapsulate all of the code needed for the table
  17. 'Local variables for the properties of the table
  18. Private moPosition As D3DVECTOR 'Current position of the table
  19. Private moTable As CD3DFrame 'D3D Mesh for the table
  20. Private mlTransparantPaddle As Boolean
  21. Public DrawTable As Boolean ' You can also turn off the table (dunno why, but let'em)
  22.  
  23. 'Position property
  24. Public Property Let Position(oPos As D3DVECTOR)
  25.     moPosition = oPos
  26. End Property
  27.  
  28. Public Property Get Position() As D3DVECTOR
  29.     Position = moPosition
  30. End Property
  31.  
  32. 'Transparent property
  33. Public Property Let Transparent(ByVal fTrans As Boolean)
  34.     Dim oMesh As CD3DMesh, oMaterial As D3DMATERIAL8
  35.     Dim lNumMaterial As Long, lCount As Long
  36.     
  37.     mlTransparantPaddle = fTrans
  38.     'now set the property
  39.     Set oMesh = moTable.FindChildObject("table", 0)
  40.     lNumMaterial = oMesh.GetMaterialCount
  41.     For lCount = 0 To lNumMaterial - 1
  42.         oMaterial = oMesh.GetMaterial(lCount)
  43.         If fTrans Then
  44.             oMaterial.diffuse.a = 0.5
  45.         Else
  46.             oMaterial.diffuse.a = 1
  47.         End If
  48.         oMesh.SetMaterial lCount, oMaterial
  49.     Next
  50. End Property
  51.  
  52. Public Property Get Transparent() As Boolean
  53.     Transparent = mlTransparantPaddle
  54. End Property
  55.  
  56. 'Methods
  57. Public Sub Init(ByVal sMedia As String, sFile As String)
  58.     Set moTable = D3DUtil_LoadFromFile(AddDirSep(sMedia) & sFile, Nothing, Nothing)
  59. End Sub
  60.  
  61. Public Sub Render(dev As Direct3DDevice8)
  62.     Dim matTable As D3DMATRIX
  63.     If DrawTable Then
  64.         'Now the table
  65.         D3DXMatrixIdentity matTable
  66.         D3DXMatrixTranslation matTable, moPosition.X, moPosition.Y, moPosition.z
  67.         moTable.SetMatrix matTable
  68.         moTable.Render g_dev
  69.     End If
  70. End Sub
  71.  
  72. Public Sub CleanupFrame()
  73.     moTable.Destroy
  74.     Set moTable = Nothing
  75. End Sub
  76.  
  77. Public Function FadeMesh(FadeInterval As Single) As Boolean
  78.     Dim lNumMaterial As Long
  79.     Dim lCount As Long
  80.     Dim oMaterial As D3DMATERIAL8
  81.     Dim fDoneFading As Boolean
  82.     Dim oMesh As CD3DMesh
  83.     Dim nInternalInterval As Single
  84.     Static lFadeTime As Long
  85.     
  86.     FadeMesh = True
  87.     nInternalInterval = FadeInterval
  88.     If lFadeTime = 0 Then
  89.         lFadeTime = timeGetTime
  90.         Exit Function 'We'll do the fade next render pass
  91.     End If
  92.     nInternalInterval = (((timeGetTime - lFadeTime) / 1000000) * nInternalInterval)
  93.     
  94.     fDoneFading = True
  95.     If Not DrawTable Then Exit Function
  96.     Set oMesh = moTable.FindChildObject("table", 0)
  97.     lNumMaterial = oMesh.GetMaterialCount
  98.     For lCount = 0 To lNumMaterial - 1
  99.         oMaterial = oMesh.GetMaterial(lCount)
  100.         If nInternalInterval > 0 And oMaterial.diffuse.a <= 1 Then
  101.             oMaterial.diffuse.a = oMaterial.diffuse.a + nInternalInterval
  102.             fDoneFading = False
  103.         ElseIf nInternalInterval < 0 And oMaterial.diffuse.a >= -1 Then
  104.             oMaterial.diffuse.a = oMaterial.diffuse.a + nInternalInterval
  105.             fDoneFading = False
  106.         End If
  107.         oMesh.SetMaterial lCount, oMaterial
  108.     Next
  109.     FadeMesh = fDoneFading
  110. End Function
  111.  
  112. Private Sub Class_Initialize()
  113.     DrawTable = True
  114.     Set moTable = Nothing
  115. End Sub
  116.  
  117. Private Sub Class_Terminate()
  118.     If Not moTable Is Nothing Then moTable.Destroy
  119.     Set moTable = Nothing
  120. End Sub
  121.